<template>
	<view class="recordBox">
		<view class="recordItem" v-for="(item,index) in 2">
			<view class="title">挂号记录</view>
			<view class="contentList">
				<view class="contentItem">
					<view class="label">编号</view>
					<view class="value">wx852456123789963</view>
				</view>
				<view class="contentItem">
					<view class="label">姓名</view>
					<view class="value">小明</view>
				</view>
				<view class="contentItem">
					<view class="label">检测项目</view>
					<view class="value">{{recordType==1?'检查报告':recordType==2?'检验报告':'核酸报告'}}</view>
				</view>
			</view>
			<view class="showDetail" @click="downloadFile">下载附件</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//报告类型1检查2检验3核酸
				recordType: 1
			}
		},
		onLoad(options) {
			if (options.type) {
				this.recordType = options.type
				uni.setNavigationBarTitle({
					title: this.recordType == 1 ? '检查报告' : this.recordType == 2 ? '检验报告' : '核酸报告'
				})
			}
		},
		methods: {
			// 下载附件
			downloadFile() {
				var that = this
				//加载框动画
				uni.showLoading({
					title: '正在下载……'
				});
				uni.downloadFile({
					url: 'http://192.168.0.146:6719/1.pdf', //下载地址接口返回
					success: (data) => {
						console.log('打印data', data)
						if (data.statusCode === 200) {
							//隐藏加载框
							uni.hideLoading();
							//文件保存到本地
							uni.saveFile({
								tempFilePath: data.tempFilePath, //临时路径
								success: function(res) {
									//自动打开文档查看
									setTimeout(() => {
										var filePath = res.savedFilePath;
										uni.openDocument({ //新开页面打开文档，支持格式：doc, xls, ppt, pdf, docx, xlsx, pptx。
											filePath: filePath,
											showMenu: true,
											success: function(res) {
												console.log('打开文档成功');
											}
										});
									}, 2000)
								}
							});
						}
					},
					fail: (err) => {
						console.log(err);
						uni.showToast({
							icon: 'none',
							mask: true,
							title: '文件下载失败',
						});
					},
				});
			}
		},
	}
</script>
<style>
	page {
		width: 100%;
		height: 100%;
		background: #F8F8F8;
	}
</style>
<style scoped lang="scss">
	.recordBox {
		height: 100%;
		padding: 0 40rpx;

		.recordItem {
			margin-top: 20rpx;
			background-color: #FFFFFF;

			.title {
				height: 66rpx;
				padding: 0 20rpx;
				line-height: 66rpx;
				background: #E1E1E1;
				font-size: 32rpx;
				color: #141414;
			}

			.contentList {
				display: flex;
				flex-direction: column;
				font-size: 28rpx;
				color: #6D6D6D;

				.contentItem {
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-bottom: 1px dashed #C1C1C1;
					height: 66rpx;
					padding: 0 20rpx;
					line-height: 66rpx;
				}
			}

			.showDetail {
				color: #548AFB;
				padding: 20rpx 0;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>
